﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
 @*   @Html.Partial("ViewLibrary")*@
    <title>Index</title>
     <link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/themes/icon.css">
    <link href="~/Content/Styles/Order.css" rel="stylesheet" />
    <script type="text/javascript" src="~/Content/jquery-easyui-1.4.2/jquery.min.js"></script>
    <script type="text/javascript" src="~/Content/jquery-easyui-1.4.2/jquery.easyui.min.js"></script>
    <script src="~/Content/jquery-easyui-1.4.2/locale/easyui-lang-zh_CN.js"></script>
    <link href="~/Content/Styles/Order.css" rel="stylesheet" />
    <script>
        $(document).ready(function () {//控制增删查改的权限
            $.post("/MerchantsIntegralManage/getPower", function (database) {
                if (database != "") {
                    $('#btndetail').linkbutton('enable');
                    if (database.Add == 1) {
                        $('#BtnAdd').linkbutton('enable');
                    }
                    if (database.Dell == 1) {
                        $('#BtnDel').linkbutton('enable');
                    }
                    if (database.Edit == 1) {
                        $('#BtnEdit').linkbutton('enable');
                    }
                }
            })
            GetOrderMer_edit();
            GetOrderMer_detail();
            GetOrderMer_add();
            GetMerInt();
        });
        //修改绑定
        function GetOrderMer_edit() {
            $.get("/MerchantsIntegralManage/getMer", {}, function (database) {
                $('#MerName').combobox({
                    valueField: 'MerID',
                    textField: 'MerName',
                    data: database
                });
            })
        }
        //明细绑定
        function GetOrderMer_detail() {
            $.get("/MerchantsIntegralManage/getMer", {}, function (database) {
                $('#d_MerName').combobox({
                    valueField: 'MerID',
                    textField: 'MerName',
                    data: database
                });
            })
        }
        //新增绑定
        function GetOrderMer_add() {
            $.get("/MerchantsIntegralManage/getMer", {}, function (database) {
                $('#a_MerName').combobox({
                    valueField: 'MerID',
                    textField: 'MerName',
                    data: database
                });
            })
        }

        var IntID;

        //获取商户的积分
        function GetMerInt() {
            var grid = $('#tab').datagrid({
                panelWidth: 500,
                idField: 'IntID',
                textField: 'IntID',
                url: '/MerchantsIntegralManage/getMerInt',
                method: 'post',
                singleSelect: true,
                pageSize: 10,
                pageList: [10],
                striped:true,
                pagination: true,
                rownumbers: true,
                fitColumns: true,
                columns: [[
                      { field: 'IntID', title: '积分ID', width: 80, align: 'center' },
                    { field: 'MerName', title: '积分商户', width: 80, align: 'center' },
                {
                    field: 'IntUn', title: '积分转换单位', width: 80, align: 'center', formatter: function (val, rowdata, index) {
                        if (val == 1) {
                            return '分';
                        } else if (val == 2) {
                            return '角';
                        } else if (val == 3) {
                            return '元';
                        }
                    }
                },
            {
                field: 'IntY', title: '转换金额处理', width: 80, align: 'center', formatter: function (val, rowdata, index) {
                    if (val == 1) {
                        return '非整数时，小数点忽略';
                    } else if (val == 2) {
                        return '非整数时，小数点四舍五入';
                    } else if (val == 3) {
                        return '非整数时，小数点进一';
                    }
                }
            },
        { field: 'IntChe', title: '积分转换率', width: 80, align: 'center' },
        {
            field: 'IsOpen', title: '是否启用', width: 80, align: 'center', formatter: function (val, rowdata, index) {
                if (val == 1) {
                    return '启用';
                } else if (val == 0) {
                    return '不启用';
                } 
            }
        }
                ]],
                toolbar: '#tb1'
            });
        }

        //添加商户的积分
        function AddDialog() {
            filePath = "";
            $('#addDialog').dialog('open').dialog('setTitle', '新增商户积分');
            $("#a_MerName").combobox("setValue", "");
            $("#a_IsOpen").attr('checked', false);
            $("#a_IntUn").combobox("setValue", 1);
            $("#a_IntY").combobox("setValue", 1);
            $("#a_IntChe").textbox("setValue", "0");
            document.getElementById("a_IsOpen").disabled = false;
            document.getElementById("a_IntChe").readOnly = false;
            document.getElementById("add").style.display = "block";
        }

        //修改商户的积分
        function UpdateDialog() {
            filePath = "";
            var UpdateInfoID = $("#tab").datagrid("getSelections");
            if (UpdateInfoID.length == 1) {
                $("#editDialog").dialog("open").dialog("setTitle", "修改商户积分");
                BingUpdate();
            }
            else {
                $.messager.alert("友情提示", "每次只能修改一行数据，你已经选择了<font color='red' size='2'>" + UpdateInfoID.length + "</font>行");
            }
        }

        //删除商户的积分
        function DeleteDialog() {
            //获取到商户的积分ID
            //首先获取选中的商户的积分的所有信息
            var checkdata = $("#tab").datagrid("getSelections");//获取整行数据
            if (checkdata.length == 1) {
                var checkdata = $("#tab").datagrid("getSelections")[0];//获取整行数据
                var postdata = {
                    IntID: checkdata.IntID,//积分ID
                    MerID: checkdata.MerID,//对应商户
                    IntUn: checkdata.IntUn,//积分转换单位
                    IntY: checkdata.IntY,//转换金额处理
                    IntChe: checkdata.IntChe,//积分转换率
                    IsOpen: checkdata.IsOpen//是否启用
                };
                //发送异步请求删除数据
                $.messager.confirm("删除信息", "您确认删除<font color='Red' size='1'>" + checkdata.MerName + "</font>这个商户积分吗？", function (ok) {
                    if (ok) {
                        $.post("/MerchantsIntegralManage/Submit?Tag=" + 3, postdata, function (data) {
                            if (data == "1") {
                                $.messager.alert("友情提示", "删除成功");
                                $("#tab").datagrid('reload');
                                //GetMerInt();
                            }
                            else {
                                $.messager.alert("友情提示", "删除失败:" + data);
                            }
                        });
                    }
                    });
            }
            else {
                $.messager.alert("友情提示", "每次只能删除一行数据，你已经选择了<font color='red' size='2'>" + checkdata.length + "</font>行");
            }
        }

        //商户的积分明细对话话框
        function DetailDialog() {
            var UpdateInfoID = $("#tab").datagrid("getSelections");
            if (UpdateInfoID.length == 1) {
                $("#detailDialog").dialog("open").dialog("setTitle", "商户积分明细");
                Bingdetail();
                $('input,select,textarea', $('form[id="detailController"]')).prop('readonly', true);
                $("#d_MerName").combobox('disable');
                $("#d_IntUn").combobox('disable');
                $("#d_IntY").combobox('disable');
                document.getElementById("d_IsOpen").disabled = true; //是否启用
            }
            else {
                $.messager.alert("友情提示", "每次只能查看一行数据，你已经选择了<font color='red' size='2'>" + UpdateInfoID.length + "</font>行");
            }
        }

        //获取修改商品信息
        function BingUpdate() {
            //首先获取选中的商品信息
            var checkdata = $("#tab").datagrid("getSelections")[0];
            if (checkdata != null) {
                IntID = checkdata.IntID; 
                //alert(checkdata.MerID);
                $("#MerName").combobox("setValue", checkdata.MerID);
                if (checkdata.IsOpen == 0) {
                    $("#IsOpen").attr('checked', false);
                }
                else {
                    $("#IsOpen").attr('checked', true);
                }
                $("#MerName").prop('readonly',true);
                $("#IntUn").combobox("setValue", checkdata.IntUn);
                $("#IntY").combobox("setValue", checkdata.IntY);
                $("#IntChe").textbox("setValue", checkdata.IntChe);
            }
        }
        //详细
        function Bingdetail() {
            //首先获取选中的商品信息
            var checkdata = $("#tab").datagrid("getSelections")[0];
            if (checkdata != null) {
                IntID = checkdata.IntID;
                $("#d_MerName").combobox("setValue", checkdata.MerName);
                if (checkdata.IsOpen == 0) {
                    $("#d_IsOpen").attr('checked', false);
                }
                else {
                    $("#d_IsOpen").attr('checked', true);
                }
                $("#d_IntUn").combobox("setValue", checkdata.IntUn);
                $("#d_IntY").combobox("setValue", checkdata.IntY);
                $("#d_IntChe").textbox("setValue", checkdata.IntChe);
            }
        }

        // 修改
        function editOnSubmit() {
            var Tag = "";
            var IntMer = $("#MerName").combobox("getValue");
            var IntUn = $('#IntUn').combobox('getValue');
            var IntY = $('#IntY').combobox('getValue');
            var IntChe = $('#IntChe').textbox('getValue');
            var IsOpen = [];
            var Tag = 2;
            $('input[name="IsOpen"]:checked').each(function () {
                IsOpen.push($(this).val());
            })
            if (IsOpen == 1) {
                var IsOpen = 1;
            }
            else {
                var IsOpen = 0;
            }
            if (IntUn != "" && IntY != "" && IntChe != "") {
                var postdata = {
                    IntID: IntID,//积分ID
                    MerID: IntMer,//对应商户
                    IntUn: IntUn,//积分转换单位
                    IntY: IntY,//转换金额处理
                    IntChe: IntChe,//积分转换率
                    IsOpen: IsOpen//是否启用
                };
                $.post("/MerchantsIntegralManage/Submit?Tag=" + Tag, postdata, function (date) {
                    if (date == "1") {
                        $.messager.alert("友情提示", "更新成功");
                        $("#editDialog").dialog('close');
                        $("#tab").datagrid('reload');
                        //GetMerInt();
                    }
                    else {
                        $.messager.alert("友情提示", "修改失败，请检查");
                    }
                });
            }
            else {
                $.messager.alert("提示", "请输入正确的值");
            }
        }

        //新增
        function AddOnSubmit() {
            var Tag = "";
            var IntMer = $("#a_MerName").combobox("getValue");
            var IntUn = $('#a_IntUn').combobox('getValue');
            var IntY = $('#a_IntY').combobox('getValue');
            var IntChe = $('#a_IntChe').textbox('getValue');
            var IsOpen = [];
            Tag = 1
            $('input[name="a_IsOpen"]:checked').each(function () {
                IsOpen.push($(this).val());
            })
            if (IsOpen == 1) {
                var IsOpen = 1;
            }
            else {
                var IsOpen = 0;
            }
            if (IntUn != "" && IntY != "" && IntChe != "") {
                var postdata = {
                    IntID: IntID,//积分ID
                    MerID: IntMer,//对应商户
                    IntUn: IntUn,//积分转换单位
                    IntY: IntY,//转换金额处理
                    IntChe: IntChe,//积分转换率
                    IsOpen: IsOpen,//是否启用
                    IntState:1
                };
                $.post("/MerchantsIntegralManage/Submit?Tag=" + Tag, postdata, function (date) {
                    if (date == "1") {
                        $.messager.alert("友情提示", "新增成功");
                        $("#addDialog").dialog('close');
                        $("#tab").datagrid('reload');
                        //GetMerInt();
                    }
                    else {
                        $.messager.alert("友情提示", "新增失败，请检查");
                    }
                });
            }
            else {
                $.messager.alert("提示", "请输入正确的值");
            }
        }

    </script>
</head>
<body>
    <div id="tb1" style="padding-top: 5px; margin-left: 5px;">
        <button id="btndetail" onclick="DetailDialog()" class="easyui-linkbutton" data-options="iconCls:'icon-more'">明细</button>
        <button id="BtnAdd" onclick="AddDialog()" class="easyui-linkbutton" data-options="iconCls:'icon-add'">添加</button>
        <button id="BtnEdit" onclick="UpdateDialog()" class="easyui-linkbutton" data-options="iconCls:'icon-edit'">编辑</button>
        <button id="BtnDel" onclick="DeleteDialog()" class="easyui-linkbutton" data-options="iconCls:'icon-cut'">删除</button>
    </div>
    <div>
        <table id="tab" style="margin: 0px; padding: 0px;"></table>
    </div>

    @*修改*@
    <div id="editDialog" class="easyui-dialog" style="width: 400px; padding: 10px; height: 315px;top: 5px;" closed="true" resizable="true" modal="true" buttons="#dlg-buttons" align="center">
        <form id="editController" method="post" novalidate="novalidate">
            <div style="padding-top:10px; text-align: center">
                <table cellpadding="2" id="IntTable" style="width: 100%; height: 100%;">
                    <tr>
                        <td style="text-align: right">
                            <input type="checkbox" id="IsOpen" name="IsOpen" value="1" />
                        </td>
                        <td class="IntM-td-2">是否启用积分</td>
                    </tr>
                    <tr>
                        <td class="IntM-td-1">积分商户：</td>
                        <td class="IntM-td-2">
                            <input class="easyui-combobox" type="text" style="width: 199px; " id="MerName" name="MerName"/>
                        </td>
                    </tr>
                    <tr>
                        <td class="IntM-td-1">积分转换单位：</td>
                        <td class="IntM-td-2">
                            <select class="easyui-combobox" type="text" style="width: 199px" id="IntUn" name="IntUn">
                                <option value="1">分</option>
                                <option value="2">角</option>
                                <option value="3">元</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td class="IntM-td-1">转换金额处理：</td>
                        <td class="IntM-td-2">
                            <select class="easyui-combobox" style="width: 199px" type="text" id="IntY" name="IntY">
                                <option value="1">非整数时，小数点忽略</option>
                                <option value="2">非整数时，小数点四舍五入</option>
                                <option value="3">非整数时，小数点进一</option>
                            </select></td>
                    </tr>
                    <tr>
                        <td class="IntM-td-1">积分转换率：</td>
                        <td class="IntM-td-2">
                            <input class="easyui-textbox" style="width: 199px" type="text" id="IntChe" name="IntChe" />
                        </td>
                    </tr>
                    <tr>
                        <td></td>
                        <td style="text-align: left;">
                            <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-ok" id="ok" style="width:60px;height:30px" onclick="editOnSubmit()">确认</a>
                        </td>
                    </tr>
                </table>
            </div>
        </form>
    </div>

    @* 明细 *@
    <div id="detailDialog" class="easyui-dialog" style="width: 400px; padding: 10px; height: 315px;top: 5px;" closed="true" resizable="true" modal="true" buttons="#dlg-buttons" align="center">
        <form id="detailController" method="post" novalidate="novalidate">
            <div style="padding-top:10px; text-align: center">
                <table cellpadding="2" id="detailTable" style="width: 100%; height: 100%;">
                    <tr>
                        <td style="text-align: right">
                            <input type="checkbox" id="d_IsOpen" name="IsOpen" value="1" />
                        </td>
                        <td class="IntM-td-2">是否启用积分</td>
                    </tr>
                    <tr>
                        <td class="IntM-td-1">积分商户：</td>
                        <td class="IntM-td-2">
                            <input class="easyui-combobox" type="text" style="width: 199px; " id="d_MerName" name="d_MerName"/>
                        </td>
                    </tr>
                    <tr>
                        <td class="IntM-td-1">积分转换单位：</td>
                        <td class="IntM-td-2">
                            <select class="easyui-combobox" type="text" style="width: 199px" id="d_IntUn" name="d_IntUn">
                                <option value="1">分</option>
                                <option value="2">角</option>
                                <option value="3">元</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td class="IntM-td-1">转换金额处理：</td>
                        <td class="IntM-td-2">
                            <select class="easyui-combobox" style="width: 199px" type="text" id="d_IntY" name="d_IntY">
                                <option value="1">非整数时，小数点忽略</option>
                                <option value="2">非整数时，小数点四舍五入</option>
                                <option value="3">非整数时，小数点进一</option>
                            </select></td>
                    </tr>
                    <tr>
                        <td class="IntM-td-1">积分转换率：</td>
                        <td class="IntM-td-2">
                            <input class="easyui-textbox" style="width: 199px" type="text" id="d_IntChe" name="IntChe" />
                        </td>
                    </tr>
                </table>
            </div>
        </form>
    </div>

    @*新增*@
    <div id="addDialog" class="easyui-dialog" style="width: 400px; padding: 10px; height: 315px;top: 5px;" closed="true" resizable="true" modal="true" buttons="#dlg-buttons" align="center">
        <form id="addController" method="post" novalidate="novalidate">
            <div style="padding-top:10px; text-align: center">
                <table cellpadding="2" id="addTable" style="width: 100%; height: 100%;">
                    <tr>
                        <td style="text-align: right">
                            <input type="checkbox" id="a_IsOpen" name="a_IsOpen" value="1" />
                        </td>
                        <td class="IntM-td-2">是否启用积分</td>
                    </tr>
                    <tr>
                        <td class="IntM-td-1">积分商户：</td>
                        <td class="IntM-td-2">
                            <input class="easyui-combobox" type="text" style="width: 199px; " id="a_MerName" name="a_MerName"/>
                        </td>
                    </tr>
                    <tr>
                        <td class="IntM-td-1">积分转换单位：</td>
                        <td class="IntM-td-2">
                            <select class="easyui-combobox" type="text" style="width: 199px" id="a_IntUn" name="a_IntUn">
                                <option value="1">分</option>
                                <option value="2">角</option>
                                <option value="3">元</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td class="IntM-td-1">转换金额处理：</td>
                        <td class="IntM-td-2">
                            <select class="easyui-combobox" style="width: 199px" type="text" id="a_IntY" name="a_IntY">
                                <option value="1">非整数时，小数点忽略</option>
                                <option value="2">非整数时，小数点四舍五入</option>
                                <option value="3">非整数时，小数点进一</option>
                            </select></td>
                    </tr>
                    <tr>
                        <td class="IntM-td-1">积分转换率：</td>
                        <td class="IntM-td-2">
                            <input class="easyui-textbox" style="width: 199px" type="text" id="a_IntChe" name="a_IntChe" />
                        </td>
                    </tr>
                    <tr>
                        <td></td>
                        <td style="text-align: left;">
                            <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-ok" id="add" style="width:60px;height:30px" onclick="AddOnSubmit()">确认</a>
                        </td>
                    </tr>
                </table>
            </div>
        </form>
    </div>
</body>
</html>
